<?php
/**
 * 
 * @author huangjian E-mail:870596179@qq.com
 * @version 创建时间：2016年10月26日 下午4:32:27 
 * 类说明
 */
class SuggestionAction extends BaseAction{
	/**
	 * @authority 浏览
	 */
	public function index(){
		$this->display('index');
	}
	
	//列表
	public function getAllData(){
		$Model = M($this->getActionName());
		$map = $this->loadSeachCondition();
		$map['a.flag'] = 1;
		$where = $this->loadSeachCondition();
		$where['flag'] = 1;
		$total = $Model->where($where)->count();// 查询满足要求的总记录数
		$page = json_decode($this->pageParam($total));
		if(!empty($page->sort)){
			$sort = 'a.'.$page->sort;
		}else{
			$sort = $page->sort;
		}
		$data = $Model->alias('a')->join('left join __USER__ as b on b.id = a.user_id')->field('a.id,a.user_id,a.content,a.feedback,a.create_time,a.flag,b.username')->where($map)->limit($page->firstRow,$page->listRows)->order($sort)->select();
		$vo = $this->toJosnForGird($data,$page);
		echo json_encode($vo);
	}
	
	/**
	 * 组装条件
	 * @return multitype:multitype:string
	 */
	public function loadSeachCondition(){
		$map = array();
		return $map;
	}
	
	public function feedback(){
		$Model = M($this->getActionName());
		$map[$Model->getPk()] = $_REQUEST['id'];
		$vo = $Model->where($map)->find();
		$this->assign('vo',$vo);
		$this->display();
	}
	
	/**
	 * 更新
	 */
	public function update() {
		$Model = M($this->getActionName());$NoticeModel = M("Notice");
		if(false === $Model->create()) {
			$this->error($Model->getError());
		}
		$param = $Model->create();
		// 更新数据
		if(false !== $Model->save($param)) {
			if($_REQUEST['noticeType'] == 1){
				$data['is_all'] = 1;
				$data['type'] = 0;
				$data['user_id'] = $_REQUEST['userId'];
				$data['message'] = $_REQUEST['feedback'];
				$data['is_push'] = 1;
				$data['create_time'] = time();
				$data['flag'] = 1;
				$NoticeModel->add($data);
			}
			$this->ajaxReturn(1,L('ADMIN_EDIT_SUCCESS'),1);
		} else {
			$this->ajaxReturn(0,L('ADMIN_EDIT_ERROR'),0);
		}
	}
	
}